<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for c:\program files\python26\lib\site-packages\modbus_tk-0.3-py2.6.egg\modbus_tk\hooks</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
function toggle_lines(btn, cls) {
    var btn = $(btn);
    var hide = "hide_"+cls;
    if (btn.hasClass(hide)) {
        $("#source ."+cls).removeClass(hide);
        btn.removeClass(hide);
    }
    else {
        $("#source ."+cls).addClass(hide);
        btn.addClass(hide);
    }
}
</script>
</head>
<body>
<div id='header'>
    <div class='content'>
        <h1>Coverage for <b>c:\program files\python26\lib\site-packages\modbus_tk-0.3-py2.6.egg\modbus_tk\hooks</b> :
            <span class='pc_cov'>25%</span>
        </h1>
        <h2 class='stats'>
            26 statements
            <span class='run hide_run' onclick='toggle_lines(this, "run")'>8 run</span>
            <span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
            <span class='mis' onclick='toggle_lines(this, "mis")'>18 missing</span>
            
                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>0 partial</span>
            
        </h2>
    </div>
</div>

<div id='source'>
<table cellspacing='0' cellpadding='0'>
<tr>
<td class='linenos' valign='top'>
<p class='pln'>1</p>
<p class='pln'>2</p>
<p class='stm run hide_run'>3</p>
<p class='pln'>4</p>
<p class='pln'>5</p>
<p class='pln'>6</p>
<p class='pln'>7</p>
<p class='pln'>8</p>
<p class='pln'>9</p>
<p class='pln'>10</p>
<p class='pln'>11</p>
<p class='stm run hide_run'>12</p>
<p class='stm run hide_run'>13</p>
<p class='pln'>14</p>
<p class='stm run hide_run'>15</p>
<p class='stm run hide_run'>16</p>
<p class='pln'>17</p>
<p class='stm run hide_run'>18</p>
<p class='pln'>19</p>
<p class='pln'>20</p>
<p class='pln'>21</p>
<p class='pln'>22</p>
<p class='pln'>23</p>
<p class='pln'>24</p>
<p class='pln'>25</p>
<p class='pln'>26</p>
<p class='pln'>27</p>
<p class='pln'>28</p>
<p class='pln'>29</p>
<p class='pln'>30</p>
<p class='pln'>31</p>
<p class='pln'>32</p>
<p class='pln'>33</p>
<p class='pln'>34</p>
<p class='pln'>35</p>
<p class='pln'>36</p>
<p class='pln'>37</p>
<p class='pln'>38</p>
<p class='pln'>39</p>
<p class='pln'>40</p>
<p class='pln'>41</p>
<p class='pln'>42</p>
<p class='pln'>43</p>
<p class='pln'>44</p>
<p class='pln'>45</p>
<p class='pln'>46</p>
<p class='pln'>47</p>
<p class='pln'>48</p>
<p class='pln'>49</p>
<p class='pln'>50</p>
<p class='pln'>51</p>
<p class='pln'>52</p>
<p class='pln'>53</p>
<p class='pln'>54</p>
<p class='pln'>55</p>
<p class='pln'>56</p>
<p class='pln'>57</p>
<p class='pln'>58</p>
<p class='pln'>59</p>
<p class='pln'>60</p>
<p class='stm mis'>61</p>
<p class='stm mis'>62</p>
<p class='stm mis'>63</p>
<p class='stm mis'>64</p>
<p class='stm mis'>65</p>
<p class='pln'>66</p>
<p class='stm run hide_run'>67</p>
<p class='pln'>68</p>
<p class='stm mis'>69</p>
<p class='stm mis'>70</p>
<p class='stm mis'>71</p>
<p class='pln'>72</p>
<p class='stm mis'>73</p>
<p class='pln'>74</p>
<p class='stm run hide_run'>75</p>
<p class='pln'>76</p>
<p class='stm mis'>77</p>
<p class='stm mis'>78</p>
<p class='stm mis'>79</p>
<p class='stm mis'>80</p>
<p class='stm mis'>81</p>
<p class='stm mis'>82</p>
<p class='stm mis'>83</p>
<p class='stm mis'>84</p>
<p class='stm mis'>85</p>
<p class='pln'>86</p>
    
</td>
<td class='text' valign='top'>
<p class='pln'><span class='com'>#!/usr/bin/env python</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># -*- coding: utf-8 -*-</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> Modbus TestKit: Implementation of Modbus protocol in python</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'></span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> (C)2009 - Luc Jean - luc.jean@gmail.com</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> (C)2009 - Apidev - http://www.apidev.fr</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'></span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> This is distributed under GNU LGPL license, see license.txt</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>from</span> <span class='nam'>__future__</span> <span class='key'>import</span> <span class='nam'>with_statement</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>threading</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>_lock</span> <span class='op'>=</span> <span class='nam'>threading</span><span class='op'>.</span><span class='nam'>RLock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>_hooks</span> <span class='op'>=</span> <span class='op'>{</span><span class='op'>}</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>install_hook</span><span class='op'>(</span><span class='nam'>name</span><span class='op'>,</span> <span class='nam'>fct</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Install one of the following hook</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuMaster.before_open((master,))</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuMaster.after_close((master,) </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuMaster.before_send((master, request)) returns modified request or None </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuMaster.after_recv((master, response)) returns modified response or None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuServer.before_close((server, ))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuServer.after_close((server, ))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuServer.before_open((server, ))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuServer.after_open(((server, ))&nbsp; &nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuServer.after_read((server, request)) returns modified request or None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuServer.before_write((server, response))&nbsp; returns modified response or None </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_rtu.RtuServer.on_error((server, excpt))</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpMaster.before_connect((master, ))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpMaster.after_connect((master, ))&nbsp; &nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpMaster.before_close((master, ))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpMaster.after_close((master, ))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpMaster.before_send((master, request))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpMaster.after_recv((master, response))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpServer.on_connect((server, client, address))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpServer.on_disconnect((server, sock))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpServer.after_recv((server, sock, request)) returns modified request or None&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpServer.before_send((server, sock, response)) returns modified response or None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus_tcp.TcpServer.on_error((server, sock, excpt))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus.Master.before_send((master, request)) returns modified request or None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus.Master.after_send((master))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus.Master.after_recv((master, response)) returns modified response or None&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus.Slave.handle_request((slave, request_pdu)) returns modified response or None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus.Slave.on_handle_broadcast((slave, response_pdu)) returns modified response or None&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus.Slave.on_exception((slave, function_code, excpt))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus.Databank.on_error((db, excpt, request_pdu))&nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus.Server.before_handle_request((server, request)) returns modified request or None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; modbus.Server.after_handle_request((server, response)) returns modified response or None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>with</span> <span class='nam'>_lock</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_hooks</span><span class='op'>[</span><span class='nam'>name</span><span class='op'>]</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>fct</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>KeyError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_hooks</span><span class='op'>[</span><span class='nam'>name</span><span class='op'>]</span> <span class='op'>=</span> <span class='op'>[</span><span class='nam'>fct</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>uninstall_hook</span><span class='op'>(</span><span class='nam'>name</span><span class='op'>,</span> <span class='nam'>fct</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;remove the function from the hooks&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>with</span> <span class='nam'>_lock</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>fct</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_hooks</span><span class='op'>[</span><span class='nam'>name</span><span class='op'>]</span><span class='op'>.</span><span class='nam'>remove</span><span class='op'>(</span><span class='nam'>fct</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>_hooks</span><span class='op'>[</span><span class='nam'>name</span><span class='op'>]</span><span class='op'>[</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>call_hooks</span><span class='op'>(</span><span class='nam'>name</span><span class='op'>,</span> <span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;call the function associated with the hook and pass the given args&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>with</span> <span class='nam'>_lock</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>fct</span> <span class='key'>in</span> <span class='nam'>_hooks</span><span class='op'>[</span><span class='nam'>name</span><span class='op'>]</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>retval</span> <span class='op'>=</span> <span class='nam'>fct</span><span class='op'>(</span><span class='nam'>args</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>retval</span> <span class='op'>&lt;&gt;</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>retval</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>KeyError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
    
</td>
</tr>
</table>
</div>

</body>
</html>
